home *** CD-ROM | disk | FTP | other *** search
- /*
-
- File name: PSAdobe.c
-
- This file contain sample code for using the new PrGeneral APIs.
-
- */
-
- #include <PrintTraps.h>
- #include <string.h>
- #include "ATMInterface.h"
- #include "PSAdobe.h"
-
- void main(void);
- OSErr commOut(Ptr buffer, long nBytes);
-
- static struct {
- Handle data;
- long len;
- } out, fnts = {0, 0}, eps = {0, 0};
-
-
- #define pCopy(dest, src) BlockMove(src, dest, src[0]+1)
-
- void main() {
- short fi;
- long count;
- TPSAdobe a;
- unsigned short i, n;
- TPSPrimaryPPD ppd;
-
- InitGraf(&thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
-
- PrOpen();
- fnts.len = eps.len = 0;
- if (PrDrvrVers() >= 80 && PrDrvrVers() < 100) { /* API only available with PSWriter */
-
- /*** Name of PPD file ***/
-
- ppd.iOpCode = PSPrimaryPPDOp;
- ppd.lReserved = 0;
- PrGeneral((Ptr)&ppd);
- if (ppd.ppdIsRealFile) { /* has the user selected a real PPD file? */
- /* ppd.ppdFile is a file spec for the main PPD file. See doc for System 7 for
- examples of how to use it.
- */
- }
-
-
- /*** Handle fonts ***/
-
- out.len = 0;
- out.data = NewHandle(0); /* prepare our call back stuff. See commOut() below. */
-
- a.iOpCode = PSAdobeOp;
- a.lReserved = 0;
- a.reserved = 0; /* always set reserved fields to zero */
- a.appFlags = 0; /* our flags */
- a.version = kPSAdobeVersion; /* tell driver which version of PSAdobe we know about */
- a.op = commOut; /* we use the same proc for gathering data in all cases */
- a.binary = false; /* same as control in Print:Save:Binary/ASCII
- a.level2 = false; /* false == level1 compatible, true == level 2 only */
-
- /* prepare to get info for fonts */
- a.subId = PSFontInfo;
- a.is.fontInfo.data = (TPSAdobe **)NewHandle(0); /* global data */
- a.is.fontInfo.printerClass = kCNone;
- a.is.fontInfo.calcVMusage = false; /* we don't need the VMusage in this example */
-
- /* get info for fonts. */
- GetFNum("\pN Helvetica Narrow", &a.is.fontInfo.id);
- a.is.fontInfo.style = 0;
- a.is.fontInfo.psName[0] = 0; /* indicates that id/style specifies the font */
- PrGeneral((Ptr)&a);
- a.is.fontInfo.id = geneva;
- a.is.fontInfo.style = 0;
- a.is.fontInfo.psName[0] = 0;
- PrGeneral((Ptr)&a);
- pCopy(a.is.fontInfo.psName, "\pMyriadMM_245_LT_520_SE");
- PrGeneral((Ptr)&a);
- pCopy(a.is.fontInfo.psName, "\pDummyFontName"); /* should come back with a.iError == fnfErr */
- PrGeneral((Ptr)&a);
- /* a.is.fontInfo.data now contain all info we need for these fonts */
-
- /* get definitions */
- HLock((Handle)a.is.fontInfo.data);
- n = GetHandleSize((Handle)a.is.fontInfo.data)/sizeof(**a.is.fontInfo.data);
- /* n is number of reources in a.is.fontInfo.data */
-
- for (i = 0; i < n; ++i) {
- PrGeneral((Ptr)&(*a.is.fontInfo.data)[i]); /* now data is sent to commOut */
- }
-
- HUnlock((Handle)a.is.fontInfo.data);
- DisposHandle((Handle)a.is.fontInfo.data);
-
- fnts = out;
-
-
- /*** PICT to EPS conversion ***/
-
- /* Note that pict to eps has to be done outside PrOpenDoc/PrCloseDoc */
-
- out.len = 0;
- out.data = NewHandle(0); /* prepare to download an eps */
-
- a.subId = PSpict2eps;
- a.is.pict2eps.getPicProc = nil;
- a.is.pict2eps.includeFonts = includeNoFonts;
- a.is.pict2eps.title = "\pMy Picture";
- a.is.pict2eps.unlimitedFonts = 0;
- a.is.pict2eps.textSmoothing = 0;
- a.is.pict2eps.graphicsSmoothing = 0;
- a.is.pict2eps.color = kColor;
- a.is.pict2eps.fontSubstitution = true;
- a.is.pict2eps.reserved = 0;
- a.is.pict2eps.pict = GetPicture(128); /* from PSAdobe.π.rsrc */
- PrGeneral((Ptr)&a);
- eps = out;
- #ifdef __NEVER__
-
- /*** comPostScriptFile ***/
-
- The app might want to save the ps code to a file, and then included
- after PrOpenDoc as PSHandles.
- An alternative way would be to put the file in some folder, and then
- use the comPostScriptFile pic comment to send the name of the file to
- the driver. The app can specify that the file should be removed after
- it has been used. The format for this comment is:
- { Ptr p;
- Handle h
-
- p = "\pThor:file1.eps";
- if (removeWhenDone) {
- h = NewHandle(p[0]+1 + 1); /* make room for delete marker */
- (*h)[p[0]+1] = 1; /* delete file when we're done */
- }
- else {
- h = NewHandle(p[0]+1); /* just make room for file name */
- }
- BlockMove(p, *h, p[0]+1); /* copy the file name */
- PicComment(comPostScriptFile, GetHandleSize(h), h);
- }
- #endif
-
- if (fnts.len) { /* dump fonts */
- Create("\pfnts.out", 0, 'KAHL', 'TEXT');
- FSOpen("\pfnts.out", 0, &fi);
- SetEOF(fi, 0);
- count = fnts.len;
- FSWrite(fi, &count, *fnts.data);
- FSClose(fi);
- DisposHandle(fnts.data);
- }
- if (eps.len) { /* dump eps */
- Create("\peps.out", 0, 'KAHL', 'TEXT');
- FSOpen("\peps.out", 0, &fi);
- SetEOF(fi, 0);
- count = eps.len;
- FSWrite(fi, &count, *eps.data);
- FSClose(fi);
- DisposHandle(eps.data);
- }
- }
- PrClose();
- }
-
-
- OSErr commOut(Ptr buffer, long nBytes) {
- /* stuff output data data */
-
- if (out.len + nBytes > GetHandleSize(out.data)) {
- SetHandleSize(out.data, out.len + nBytes + 0x4000);
- if (MemError())
- return MemError();
- }
- BlockMove(buffer, *out.data + out.len, nBytes);
- out.len += nBytes;
- return noErr;
- }
-
- /* Note: commOut above will be called a zillion times, often with just a few bytes. There
- is no internal buffering before the call to commOut, so you better have your own. Usually,
- this is often done later. For example, writing this to disk or sending it through PAP should
- be OK, they have their own buffering.
- */
-
-
-